﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WaterBill.DTO;

namespace WaterBill.DAL
{
    class DAL_Charges : clsConnection
    {
        DataTable dtCh;
        //Lay danh sach tat ca cac thang
        public DataTable DAL_Charges_GetAll()
        {
            dtCh = new DataTable();
            try
            {
                dtCh = ExcuteQuery("GetAllCharge");
            }
            catch
            {
            }
            return dtCh;
        }

        //Lay danh sach cac thang dua vao id
        public DataTable DAL_Charges_GetById(int ChargeId)
        {
            dtCh = new DataTable();
            try
            {
                AddParameter(new SqlParameter("@ChargeId", ChargeId));
                dtCh = ExcuteQuery("GetChargeById");
            }
            catch
            {
            }
            return dtCh;
        }

        //Lay du lieu thang dua vao id lon nhat
        public DataTable DAL_Charges_GetByMaxId()
        {
            dtCh = new DataTable();
            try
            {
                dtCh = ExcuteQuery("GetChargeByMaxId");
            }
            catch 
            {
            }
            return dtCh;
        }

        //Them thang moi
        public Boolean DAL_Charges_Insert(DTO_Charges obj)
        {
            try
            {
                AddParameter(new SqlParameter("@Month", obj.Month));
                AddParameter(new SqlParameter("@Year", obj.Year));
                AddParameter(new SqlParameter("@Price", obj.Price));
                AddParameter(new SqlParameter("@Status", 1));
                if (ExcuteNonQuery("InsertCharge"))
                {
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        //Sua thang
        public Boolean DAL_Charges_Update(DTO_Charges obj)
        {
            try
            {
                AddParameter(new SqlParameter("@ChargeId", obj.ChargeId));
                AddParameter(new SqlParameter("@Price", obj.Price));
                AddParameter(new SqlParameter("@Status", obj.Status));
                if (ExcuteNonQuery("UpdateCharge"))
                {
                    return true;
                }
            }
            catch
            {
            }
            return false;
        }

        ////lay danh sach thang (group by)
        public DataTable DAL_Charge_GetAllMonth()
        {
            dtCh = new DataTable();
            try
            {
                dtCh = ExcuteQuery("GetChargeAllMonth");
            }
            catch
            {
            }
            return dtCh;
        }

        //lay danh sach nam (group by)
        public DataTable DAL_Charge_GetAllYear()
        {
            dtCh = new DataTable();
            try
            {
                dtCh = ExcuteQuery("GetChargeAllYear");
            }
            catch
            {
            }
            return dtCh;
        }

    }
}
